﻿using System;
using System.Collections.Generic;
using System.Text;
using BarCode.Bean;
using BarCode.Common;
using System.Data;
using BarCode.Module;
using MySql.Data.MySqlClient;

namespace BarCode.AccessDao
{
    public class DB02Dao
    {
        private static readonly log4net.ILog LogUtil = log4net.LogManager.GetLogger(typeof(DB02Dao));

        private MySqlHelper db02;
        public DB02Dao(string serverIp, string userId, string userPwd)
        {
            db02 = new MySqlHelper(serverIp, "db_02", userId, userPwd);
        }

        /// <summary>
        /// 判断是否可链接
        /// </summary>
        /// <returns></returns>
        public bool EnableConnect()
        {
            return db02.EnableConnect();
        }

        /// <summary>
        /// 表号检查
        /// </summary>
        /// <returns> 错误信息 </returns>
        public string checkBH(string barcode)
        {
            MySqlParameter sqlParam = new MySqlParameter("@SerialNumber", barcode);
            DataSet retSet = db02.GetDataSet(CommandType.Text, "select MeterAccepted from meters where SerialNumber = @SerialNumber ", new MySqlParameter[] { sqlParam });
            if (retSet != null && retSet.Tables.Count > 0)
            {
                DataTable dt = retSet.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    string JL = Convert.ToString(dt.Rows[0][0]);
                    if (!"合格".Equals(JL))
                    {
                        return "密封不合格";
                    }
                    else
                    {
                        return "";
                    }

                }
                else
                {
                    return "密封不存在";
                }
            }
            else
            {
                return "密封不存在";
            }
            return "";
        }


    }
}
